<?php
if (!defined("BASEPATH")) exit("No direct script access allowed");

class Acc2ins_maj extends MY_Model {

	function __construct() {
		parent::__construct();
		$this->tableName = "acc2ins_maj";
		$this->prefix = "a2im";
	}
	
	function getAcc2ins_majIds($where = NULL) {

		$qs =	"
				select
					a2im_id, a2im_ins_id
				from
					".$this->db->dbprefix.$this->tableName."
				where
					a2im_del = 0".((!is_null($where))?(" and ".$where):(""));
		$result = $this->db->query($qs);
		$getAcc2ins_majIds = array();
		if($result->num_rows()) {
			foreach ($result->result() as $row) {
				$getAcc2ins_majIds[$row->a2im_id]["a2imInsId"] = $row->a2im_ins_id;
			}
		}

		return $getAcc2ins_majIds;
	}

	function deleteAcc2ins_byDeletedInsIds($arrInsId) {

		$qs =	"
				select
					a2im_id
				from
					".$this->db->dbprefix.$this->tableName."
					join ".$this->db->dbprefix."major on maj_id = a2im_maj_id and maj_del = 0
					join ".$this->db->dbprefix."institute on ins_id = maj_ins_id and ins_del = 0 and ins_id in (".implode(",", $arrInsId).")
				where
					a2im_del = 0";
		$result = $this->db->query($qs);
		if($result->num_rows()) {
			foreach ($result->result() as $row) {
				$this->acc2ins_maj->delete($row->a2im_id);
			}
		}

		return TRUE;
	}
	
}